package com.zlm.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 疑难字枚举
 * @Author: duyufu
 * @Date: 2019/3/6 15:29
 */
public enum UncommonCharacterEnum {

    CHARACTER_1("凃","T"),
    CHARACTER_2("庒","Z"),
    CHARACTER_3("囖","L")
    ;

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    UncommonCharacterEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    //把枚举转成json
    public static String getJsonString(){
        StringBuilder builder = new StringBuilder("{");
        for(UncommonCharacterEnum uncommonCharacterEnum:UncommonCharacterEnum.values()){
            builder.append("\""+uncommonCharacterEnum.getCode()+"\":\""+ uncommonCharacterEnum.getName()+"\",");
        }
        String json=builder.substring(0, builder.length()-1)+"}";
        return json;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List getUncommonCharacter(){
        List list = new ArrayList();
        Map<String,Object> map;
        for(UncommonCharacterEnum uncommonCharacterEnum:UncommonCharacterEnum.values()){
            map= new HashMap<String, Object>();
            map.put("code", uncommonCharacterEnum.getCode());
            map.put("name", uncommonCharacterEnum.getName());
            list.add(map);
        }
        return list;
    }

    public static String getNameByCode(String code){
        for(UncommonCharacterEnum uncommonCharacterEnum:UncommonCharacterEnum.values()){
            if(code.equals(uncommonCharacterEnum.getCode())){
                return uncommonCharacterEnum.getName();
            }
        }
        return null;
    }

}
